package com.mengwen.backstage.mapper;

import com.mengwen.backstage.pojo.GetNotification;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author LiangYonghui
 * @date 2020/4/8 18:49
 * @description 获取通知表的数据访问层
 */
@Mapper
@Repository
public interface GetNotificationMapper {



    /**
     * 添加查询通知类
     * @param getNotification
     * @return
     */
    @Insert("INSERT INTO get_notification (getter_unionid,id,notice_date,sender_nickname,content) " +
            " VALUES(#{getterUnionid},#{id},#{noticeDate},#{senderNickname},#{content})")
    int insertItemByGetNotification(GetNotification getNotification);

    /**
     * 根据unionid查询未读的通知
     * @param unionid
     */
    @Select("SELECT * FROM get_notification WHERE getter_unionid = #{unionid} AND isread = 0 ")
    List<GetNotification> findNotReadNotificationByUnionid(String unionid);

    /**
     * 根据unionid设为已读
     * @param unionid
     * @return
     */
    @Update("UPDATE get_notification SET isread = 1 WHERE getter_unionid = #{unionid}")
    int setReadByUnionid(String unionid);
}
